﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace ShopShop.Models
{

    public interface IProduct
    {

    }
    //this is a Product
    public interface IBanGiayRepository:IProduct
    {
        IQueryable<Category> getCategory();
        IQueryable<Product> getProducts();
        IQueryable<Product> getProductBySubCat(string subCatId);

        Account FindAccountByID(int IDName);
        Account FindAccountByLoginName(string loginName);
        void addAccount(Account acc);

    }    

    public class BanGiayRepository : IBanGiayRepository
    {
        BanGiayEntities db = new BanGiayEntities();

        public IQueryable<Category> getCategory()
        {
            return db.Categories;
        }

        public IQueryable<Product> getProducts()
        {
            return db.Products;
        }

        public IQueryable<Product> getProductBySubCat(string subCatId)
        {
            return db.Products.Where(x => x.CategoryId == subCatId);
        }

        public Account FindAccountByID(int Id)
        {
            return db.Accounts.Where(x => x.AccountId == Id).FirstOrDefault();
        }

        public Account FindAccountByLoginName(string loginName)
        {
            return db.Accounts.FirstOrDefault(x => x.LoginName.Equals(loginName));
        }

        public void addAccount(Account acc)
        {
            db.Accounts.Add(acc);
        }

    }

    //this is a Factory
    public interface IBanHang//this is a root
    {
        IBanGiayRepository CreateProduct();
    }

    public class BanGiayFactory:IBanHang
    {
        public IBanGiayRepository CreateProduct()
        {
            return new BanGiayRepository();
        }
    }

    public enum Manufacturor
    {
        BANGIAY,
        BANQUANAO
    }
    //this is app to create Factory
    public class AppClient
    {
        public IBanHang factory;
        public AppClient(Manufacturor m)
        {
            if (m == Manufacturor.BANGIAY)
                factory = new BanGiayFactory();
        }
    }
}